// import { login, logout, getInfo } from '@/api/user'
import { login, getUserProfile } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
// import { resetRouter } from '@/router'

const state = {
  token: getToken() || '',
  userInfo: {}
}
const mutations = {
  setToken(state, newToken) {
    state.token = newToken
    setToken(newToken)
  },
  removeToken(state) {
    state.token = ''
    removeToken()
  },
  setUserInfo(state, info) {
    state.userInfo = info
  },
  removeUserInfo(state) {
    state.userInfo = {}
  }
}

const actions = {
  async userLogin(context, data) {
    const res = await login(data)
    context.commit('setToken', res.data)
  },
  async userInfo(context) {
    const res = await getUserProfile()
    console.log(res)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

